package vip.xiaonuo.supplier.modular.base.carrier.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.base.carrier.entity.SupplierCarrier;
import vip.xiaonuo.supplier.modular.base.carrier.param.SupplierCarrierAddParam;
import vip.xiaonuo.supplier.modular.base.carrier.param.SupplierCarrierEditParam;
import vip.xiaonuo.supplier.modular.base.carrier.param.SupplierCarrierIdParam;
import vip.xiaonuo.supplier.modular.base.carrier.param.SupplierCarrierPageParam;
import vip.xiaonuo.supplier.modular.base.carrier.service.SupplierCarrierService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 承运人控制器
 *
 * @author Mr.wu
 * @date  2025/03/15 19:09
 */
@Tag(name = "承运人控制器")
@RestController
@Validated
public class SupplierCarrierController {

    @Resource
    private SupplierCarrierService supplierCarrierService;

    /**
     * 获取承运人分页
     *
     * @author Mr.wu
     * @date  2025/03/15 19:09
     */
    @Operation(summary = "获取承运人分页")
    @SaCheckPermission("/supplier/base/carrier/page")
    @GetMapping("/supplier/base/carrier/page")
    public CommonResult<Page<SupplierCarrier>> page(SupplierCarrierPageParam supplierCarrierPageParam) {
        return CommonResult.data(supplierCarrierService.page(supplierCarrierPageParam));
    }

    /**
     * 添加承运人
     *
     * @author Mr.wu
     * @date  2025/03/15 19:09
     */
    @Operation(summary = "添加承运人")
    @CommonLog("添加承运人")
    @SaCheckPermission("/supplier/base/carrier/add")
    @PostMapping("/supplier/base/carrier/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierCarrierAddParam supplierCarrierAddParam) {
        supplierCarrierService.add(supplierCarrierAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑承运人
     *
     * @author Mr.wu
     * @date  2025/03/15 19:09
     */
    @Operation(summary = "编辑承运人")
    @CommonLog("编辑承运人")
    @SaCheckPermission("/supplier/base/carrier/edit")
    @PostMapping("/supplier/base/carrier/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierCarrierEditParam supplierCarrierEditParam) {
        supplierCarrierService.edit(supplierCarrierEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除承运人
     *
     * @author Mr.wu
     * @date  2025/03/15 19:09
     */
    @Operation(summary = "删除承运人")
    @CommonLog("删除承运人")
    @SaCheckPermission("/supplier/base/carrier/delete")
    @PostMapping("/supplier/base/carrier/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierCarrierIdParam> supplierCarrierIdParamList) {
        supplierCarrierService.delete(supplierCarrierIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取承运人详情
     *
     * @author Mr.wu
     * @date  2025/03/15 19:09
     */
    @Operation(summary = "获取承运人详情")
    @SaCheckPermission("/supplier/base/carrier/detail")
    @GetMapping("/supplier/base/carrier/detail")
    public CommonResult<SupplierCarrier> detail(@Valid SupplierCarrierIdParam supplierCarrierIdParam) {
        return CommonResult.data(supplierCarrierService.detail(supplierCarrierIdParam));
    }
}
